import 'dart:convert';

import 'package:yuan_hang_app/bean/dict_entity.dart';
import 'package:yuan_hang_app/widget/label_item.dart';

class ModelEntity {
  int id;
  String modelCode;
  String modelName;
  String? description;
  String? remark;
  double? price;

  ModelEntity({
    required this.id,
    required this.modelCode,
    required this.modelName,
    required this.description,
    required this.remark,
    required this.price,
  });

  factory ModelEntity.fromJson(Map<String, dynamic> json) => ModelEntity(
        id: json["id"],
        modelCode: json["modelCode"],
        modelName: json["modelName"],
        description: json["description"],
        remark: json["remark"],
        price: json["price"],
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "modelCode": modelCode,
        "modelName": modelName,
        "description": description,
        "remark": remark,
        "price": price,
      };

  ModelEntity modelEntityFromJson(String str) =>
      ModelEntity.fromJson(json.decode(str));

  String modelEntityToJson(ModelEntity data) => json.encode(data.toJson());

  static List<Map> exchangeLabelList(List<ModelEntity> entitys) {
    List<Map> list = [];
    for (ModelEntity entity in entitys) {
      list.add({"label": entity.modelName, "value": entity.modelCode,"id":entity.id});
    }
    return list;
  }
}
